<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
    <title>滚动加载</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            width: 100%;
            height: 500px;
            margin-top: 50px;
            background-color: aliceblue;
            box-sizing: border-box;
            padding: 10px 0;
            overflow: auto;
        }

        li {
            width: 90%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            color: rgb(75, 206, 75);
            font-weight: 600;
            background-color: #fff;
            border-radius: 5px;
            margin: 0 0 10px 5%;
        }
    </style>
</head>

<body>
    <ul>
        <!-- <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li> -->
    </ul>

    <script src="./scroll.js"></script>
    <script>
        var state = false; // 加载状态
        var ul = document.getElementsByTagName('ul')[0]; // 容器

        request();

        // 滚动加载
        scroll(ul, function () {
            if (state) {
                request();
            }
        });

        // 模拟请求
        function request() {
            state = false;
            setTimeout(() => {
                state = true;
                // 创建dom, 每次添加10条
                for (var i = 0; i < 10; i++) {
                    var li = document.createElement('li')
                    li.innerText = i + 1;
                    ul.appendChild(li);
                }
            }, 500)

        }

    </script>
</body>

</html>